<template>
  <div>
    <button />
  </div>
</template>

<script>
import { companyDepartmentAPI } from '@/api'
export default {
  data() {
    return {
      list: []
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    document.addEventListener('click', this.documentClick)
  },
  methods: {
    async getData() {
      const res = await companyDepartmentAPI()

      this.list = this.getchildren(res.data.depts, '')
    },

    getchildren(arr, pid = '') {
      return arr.filter((v) => {
        if (v.pid == pid) {
          v.children = this.getchildren(arr, v.id)
          return true
        }
      })
    },

    documentClick() {
      console.log(111)
    }
  }
}
</script>

<style></style>
